<template>
  <div class="_wz_cent_main _wz_deptLearning">
    <Card :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="课程名称">
          <i-input v-model="formDataSearch.trainProgramName" placeholder="请填写课程名称" clearable />
        </FormItem>
        <FormItem label="完成状态">
          <i-select v-model.number="formDataSearch.finishState" filterable placeholder="请选择完成状态" clearable>
            <Option :value="0">未完成</Option>
            <Option :value="1">已完成</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <Drawer title="参加人员" v-model="deptLearningUserType" width="1000" :draggable="true">
      <deptLearningUser v-if="deptLearningUserType" :parentSelectData="selectData"></deptLearningUser>
    </Drawer>

    <Drawer title="查看素材" v-model="materialType" width="1000" :draggable="true">
      <materialList v-if="materialType" :materialList="materialList"></materialList>
    </Drawer>

    <Spin size="large" fix v-if="spinShow"></Spin>
  </div>
</template>
<script>

import wzTbale from "../../../components/table/table";
import materialList from './materialList.vue'
import deptLearningUser from './deptLearningUser.vue'
export default {
  components: {
    wzTbale,//列表
    materialList,//课件
    deptLearningUser,//参加人员
  },
  data() {
    return {
      deptLearningUserType:false,//参加人员
      materialType:false,//视频
      materialList:[],
      spinShow:false,//本页加载
      subDeptList:[],
      searchType:false,//搜索条件
      selectData: {},
      formDataSearch: {},//搜索表单数据
      tableData: {
        url: this.apiUrl.trainTrainProgramDeptTrainProgramDeptPageList,//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 80, align: 'center', title: '序号'},
          {title: '课程名称', key: 'trainProgramName', minWidth: 200,},
          {title: '培训时长', key: 'trainProgramDeptTotalDuration', minWidth: 160, render: (h, params) => {
              return h('span', params.row.trainProgramDeptTotalDuration +' 分钟');
            }
          },
          {title: '课题数量', key: 'trainProgramDeptMaterialNumber', minWidth: 140, render: (h, params) => {
              return h('span', params.row.trainProgramDeptMaterialNumber +' 课件');
            }
          },
          {title: '培训时间', minWidth: 280, render: (h, params) => {
              return h('span', params.row.trainProgramDeptBeginDate +' - '+ params.row.trainProgramDeptEndDate);
            }
          },
          {title: '报名人数', key: 'trainProgramDeptSignUpNumber', minWidth: 100,},
          {title: '未完成人数', key: 'trainProgramDeptUnfinishedNumber', minWidth: 100,},
          {title: '完成人数', key: 'trainProgramDeptFinishedNumber', minWidth: 100,},
          {title: '运输企业', key: 'deptName', minWidth: 220,},
          {
            title: '操作', key: 'value', fixed: 'right', width: 120, render: (h, params) => {
              let operationButtons = [];
              //查看
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = params.row
                      this.deptLearningUserType = true;
                    }
                  }
                }, '查看')
              );

              if(params.row.trainProgramDeptFinish){
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //课件
                operationButtons.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.seeMaterial(params.row);
                      }
                    }
                  }, '课件')
                );
              }

              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },

    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;
    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })

  },
  methods: {//执行的方法
    //查看课件
    seeMaterial(data) {
      let that = this;
      that.materialList = [];
      that.spinShow = true;
      that.axios.post(that.apiUrl.trainTrainProgramDeptTrainProgramDeptTopicPageList, {trainProgramDeptUuid : data.uuid}).then(res => {
        if (!!res) {
          res.data.data.forEach(function (k, i) {
            let data = {};
            data.name = k.trainMaterialName;//名称
            data.typeName = k.trainMaterialTransportTypeName;//类型
            data.time = k.trainMaterialDuration;//时长
            data.mp4Url = k.trainMaterialUrl;//地址
            that.materialList.push(data);
          })

          that.spinShow = false;
          that.materialType = true;
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    //搜索
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },

  },
  watch: {//监听

  },
  props: {//接收来自父组件的数据

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>


<style lang="less">
._wz_deptLearning {
  height: 100%;
  display: flex;
  flex-direction: column;


}
</style>
